import QtQuick
import QtQuick.Controls

Window {
    width: 640
    height: 480
    visible: true
    title: qsTr("性能优化 - 大型列表")

    // 大型列表
    ComboBox {
        id: largeDataCombo
        width: 250

        popup: Popup {
            y: largeDataCombo.height
            width: largeDataCombo.width
            implicitHeight: Math.min(contentHeight, 400)
            padding: 1

            contentItem: ListView {
                clip: true
                implicitHeight: contentHeight
                model: largeDataCombo.popup.visible ? largeDataCombo.delegateModel : null
                currentIndex: largeDataCombo.highlightedIndex
                snapMode: ListView.SnapToItem
                boundsBehavior: Flickable.StopAtBounds

                // 使用延迟创建提高性能
                delegate: ItemDelegate {
                    width: parent.width
                    text: modelData
                    highlighted: largeDataCombo.highlightedIndex === index
                }

                ScrollBar.vertical: ScrollBar { }
            }
        }

        // 模拟大数据集
        Component.onCompleted: {
            var hugeModel = []
            for (var i = 0; i < 10000; i++) {
                hugeModel.push("选项 " + (i + 1))
            }
            largeDataCombo.model = hugeModel
        }
    }
}
